package servlets;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import LibraryDemo.BookManager;
import LibraryDemo.Dao.IBookDao;
import LibraryDemo.Dao.MockBookDao;
import LibraryDemo.Entity.Book;
import net.sf.json.JSONObject;

public class home extends HttpServlet{
	@Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
		PrintWriter out = response.getWriter();
		JSONObject jsonObject = new JSONObject();
		List<String> list = new ArrayList<String>();
		list.add("ABC");
		list.add("123");
		IBookDao dao = new MockBookDao();
		BookManager mgr = new BookManager(dao);
		Book bk = null;
		try{
			bk = mgr.getOneBook(1);
		}catch(Exception ex){

			String msg = ex.toString();
			out.println(msg);
		}
		jsonObject.put("book", bk);
		jsonObject.put("test", list);
		out.println(jsonObject);
		out.print("ABCHOME123, Hello World!");
		
    }
}
